package com.java2207.group1.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java2207.group1.common.LayuiPageVo;
import com.java2207.group1.mapper.BasicMapper;
import com.java2207.group1.pojo.Basic;
import com.java2207.group1.service.BasicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service("basicService")
public class BasicServiceImpl implements BasicService {
    @Autowired
    private BasicMapper basicMapper;


    @Override
    public LayuiPageVo<Basic> basicPageAll(Map<String, Object> params) {
        Integer page = Integer.parseInt(params.get("page") + "");
        Integer limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page,limit);
        List<Basic> layuiPageVo = basicMapper.basicPageAll(params);

        PageInfo<Basic> pageInfo = new PageInfo<>(layuiPageVo);
        LayuiPageVo<Basic> basicLayuiPageVo = new LayuiPageVo<>();
        basicLayuiPageVo.setCode(0);
        basicLayuiPageVo.setMsg("分页列表数据");
        basicLayuiPageVo.setCount(pageInfo.getTotal());//总记录数
        basicLayuiPageVo.setData(pageInfo.getList());//分页的列表数据


        return basicLayuiPageVo;
    }

    @Override
    public int delectBasic(int id) {
        int i = basicMapper.delectBasic(id);
        return i;
    }

    @Override
    public int addBasic(Basic basic) {
        int i = basicMapper.addBasic(basic);
        return i;
    }

    @Override
    public int updateBasic(Basic basic) {
        int i = basicMapper.updateBasic(basic);
        return i;
    }
}
